package com.lago.homework3.Exercise5;

import java.util.*;

public class Card {
    public static void main(String[] args) {
        //map集合，用来存储索引和组装好的牌。
        HashMap<Integer, String> card = new HashMap<>();

        //list集合，创建牌的索引。
        ArrayList<Integer> cardIndex = new ArrayList<>();

        //创建两个集合，用于储存花色和序号。
        List<String> color = List.of("♠", "♥", "♣", "♦");
        List<String> number = List.of("2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3");

        //安排大小王进集合
        int index = 0;
        card.put(index, "大王");
        cardIndex.add(index);
        index++;
        card.put(index, "小王");
        cardIndex.add(index);
        index++;

        //将花色和数字组合
        for (String num : number) {
            for (String col : color) {
                card.put(index, num + col);
                cardIndex.add(index);
                index++;
            }
        }
        //洗牌
        Collections.shuffle(cardIndex);

        //发牌（有三个玩家，一个底牌，底牌有三张）
        ArrayList<Integer> player1 = new ArrayList<>();
        ArrayList<Integer> player2 = new ArrayList<>();
        ArrayList<Integer> player3 = new ArrayList<>();
        ArrayList<Integer> Basic = new ArrayList<>();

        //遍历索引，获得每一张牌
        for (int i = 0; i < cardIndex.size(); i++) {
            Integer in = cardIndex.get(i);

            if (i >= 51) {
                Basic.add(in);
            } else if (i % 3 == 0) {
                player1.add(in);
            } else if (i % 3 == 1) {
                player2.add(in);
            } else if (i % 3 == 2) {
                player3.add(in);
            }
        }
        Collections.sort(player1);
        Collections.sort(player2);
        Collections.sort(player3);
        Collections.sort(Basic);

        //5、看牌
        lookCard("白起", card, player1);
        lookCard("王翦", card, player2);
        lookCard("李牧", card, player3);
        lookCard("底牌", card, Basic);
        
    }

    private static void lookCard(String name, HashMap<Integer, String> card, ArrayList<Integer> list) {
        System.out.print(name + ":");

        //获取牌的索引
        for (Integer key : list) {
            String value = card.get(key);
            System.out.print(value + " ");
        }
        System.out.println();         //打印完每个玩家进行换行

    }

}
